// Render Target Texture OpenGL
// (c) jimon game studio

#ifndef JEH_CRENDERTARGETTEXTURE_OPENGL
#define JEH_CRENDERTARGETTEXTURE_OPENGL

#include "IRenderTargetTexture.h"

#ifdef JE_RENDER_OPENGL

#include "CRender_OpenGL_Extensions.h"
#include "ILogManager.h"
#include "jeOpenGLWorkMode.h"

namespace je
{
	namespace video
	{
		//! Render Target Texture OpenGL
		class CRenderTargetTexture_OpenGL:public je::video::IRenderTargetTexture
		{
		protected:
			CRender_OpenGL_Extensions * Extensions;

			GLuint FrameBufferObject;

			ITexture * CurrentTextures[JE_MAX_RENDERTEXTURETARGET_TEXTURES];

			inline GLenum ConvertLayerToAttachment(RenderTargetTextureLayer Layer)
			{
				switch(Layer)
				{
				case RTTL_COLOR0:
					return GL_COLOR_ATTACHMENT0;
				case RTTL_COLOR1:
					return GL_COLOR_ATTACHMENT1;
				case RTTL_COLOR2:
					return GL_COLOR_ATTACHMENT2;
				case RTTL_COLOR3:
					return GL_COLOR_ATTACHMENT3;
				case RTTL_DEPTH:
					return GL_DEPTH_ATTACHMENT;
				default:
					JELOG_E("Unknown FBO layer !")
					return GL_COLOR_ATTACHMENT0;
					break;
				}
			}

			//! OpenGL Work Mode
			OpenGLWorkMode CurrentWorkMode;

		public:
			//! Constructor
			CRenderTargetTexture_OpenGL(CRender_OpenGL_Extensions * NewExtensions,OpenGLWorkMode WorkMode);

			//! Destructor
			~CRenderTargetTexture_OpenGL();

			//! Attach Texture
			u1 AttachTexture(ITexture * Texture,RenderTargetTextureLayer Layer);

			//! DeAttach Texture
			void DeAttachTexture(RenderTargetTextureLayer Layer);

			//! Get Texture
			ITexture * GetTexture(RenderTargetTextureLayer Layer);

			//! Copy To Buffer
			void CopyToBuffer(IRenderTargetTexture * Destination);

			//! Bind
			void Bind();

			//! UnBind
			void UnBind();

			//! Get FBO Id
			GLuint GetFBOId()
			{
				return FrameBufferObject;
			}
		};
	}
}

#endif
#endif
